package agh.rozproszony.DBStorage;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DataBaseTest {

    private String databaseName;
    private String databaseAddress;
    private String databasePassword;
    private String databaseUser;

    public DataBaseTest() {
        databaseName = "DB";
        databaseAddress = "localhost";
        databasePassword = "pass";
        databaseUser = "root";
    }


public Connection dataBaseConnect()
    {
        System.out.println("--------Connection Testing ------------");

        try {

                Class.forName("com.mysql.jdbc.Driver");

        } catch (ClassNotFoundException e) {

                System.out.println("Where is your MySql JDBC Driver? "
                                + "Include in your library path!");
                e.printStackTrace();
                
                return null;
        }

        System.out.println("MySql JDBC Driver Registered!");

        Connection connection = null;

        try {

                connection = DriverManager
          .getConnection("jdbc:mysql://"+databaseAddress+"/"+databaseName, databaseUser, databasePassword);

        } catch (SQLException e) {

                System.out.println("Connection Failed! Check output console");
                e.printStackTrace();
                
                return null;
        }

        if (connection != null) {
                System.out.println("You made it, take control your database now!");
                
                return connection;
        } 
        else {
                System.out.println("Failed to make connection!");
        }
        return null;
    }











}
